// 通用类型定义
export interface ApiResponse<T = any> {
  code: number
  message: string
  data: T
}

export interface PaginationParams {
  page: number
  size: number
}

export interface PaginationResponse<T = any> {
  list: T[]
  total: number
  page: number
  size: number
}

// 用户相关类型
export interface User {
  id: number
  username: string
  phone: string
  registerTime: string
  disposalCount: number
  totalWeight: number
  totalEarnings: number
  availableBalance: number
  status: 'active' | 'disabled'
}

export interface UserQuery extends PaginationParams {
  username?: string
  phone?: string
  registerTimeStart?: string
  registerTimeEnd?: string
  status?: string
}

export interface UserForm {
  username: string
  phone: string
  status: 'active' | 'disabled'
}

// 设备相关类型
export interface Device {
  id: number
  code: string
  name: string
  type: string
  location: string
  currentWeight: number
  maxCapacity: number
  status: 'online' | 'offline' | 'full' | 'error'
  lastMaintenanceTime: string
  latitude?: number
  longitude?: number
}

export interface DeviceQuery extends PaginationParams {
  code?: string
  type?: string
  status?: string
  location?: string
}

export interface DeviceForm {
  code: string
  name: string
  type: string
  location: string
  maxCapacity: number
  latitude?: number
  longitude?: number
}

// 投放相关类型
export interface DisposalRecord {
  id: number
  userId: number
  deviceId: number
  userName: string
  deviceName: string
  wasteType: string
  weight: number
  unitPrice: number
  totalAmount: number
  disposalTime: string
  status: 'normal' | 'exception'
}

export interface DisposalQuery extends PaginationParams {
  userId?: number
  deviceId?: number
  wasteType?: string
  startTime?: string
  endTime?: string
  minWeight?: number
  maxWeight?: number
}

// 质检相关类型
export interface QualityException {
  id: number
  disposalRecordId?: number
  userId: number
  deviceId: number
  userName: string
  userPhone: string
  deviceName: string
  deviceCode: string
  type: 'weight_error' | 'type_error' | 'amount_error' | 'other'
  wasteType: string
  weight: number
  originalAmount: number
  description: string
  status: 'pending' | 'processing' | 'completed' | 'ignored'
  inspectorId?: number
  inspectorName?: string
  createdAt: string
  updatedAt: string
  images?: string[]
}

export interface ExceptionQuery extends PaginationParams {
  exceptionType?: string
  status?: string
  userId?: number
  deviceId?: number
  startTime?: string
  endTime?: string
}

export interface HandleForm {
  handleType: 'deduct' | 'add' | 'none'
  adjustAmount: number
  remark: string
}

export interface QualityRecord {
  id: number
  exceptionId: number
  inspector: string
  handleType: 'deduct' | 'add' | 'none'
  adjustAmount: number
  remark: string
  handleTime: string
  status: 'completed' | 'cancelled'
}

export interface RecordQuery extends PaginationParams {
  inspector?: string
  handleType?: string
  startTime?: string
  endTime?: string
}

export interface QualityDeduction {
  id: number
  userId: number
  userName: string
  userPhone: string
  exceptionId?: number
  amount: number
  reason: string
  status: 'pending' | 'completed' | 'failed'
  operatorId: number
  operatorName: string
  createdAt: string
}

export interface DeductionRecord {
  id: number
  userId: number
  userName: string
  amount: number
  reason: string
  status: 'pending' | 'confirmed' | 'cancelled'
  createTime: string
}

export interface DeductionQuery extends PaginationParams {
  userId?: number
  status?: string
  startTime?: string
  endTime?: string
}

export interface QualityAddition {
  id: number
  userId: number
  userName: string
  userPhone: string
  exceptionId?: number
  amount: number
  reason: string
  status: 'pending' | 'completed' | 'failed'
  operatorId: number
  operatorName: string
  createdAt: string
}

export interface AdditionRecord {
  id: number
  userId: number
  userName: string
  amount: number
  reason: string
  status: 'pending' | 'confirmed' | 'cancelled'
  createTime: string
}

export interface AdditionQuery extends PaginationParams {
  userId?: number
  status?: string
  startTime?: string
  endTime?: string
}

// 清运相关类型
export interface CleanupTask {
  id: number
  deviceId: number
  deviceName: string
  priority: 'low' | 'medium' | 'high'
  status: 'pending' | 'assigned' | 'in_progress' | 'completed'
  assignedTo?: string
  createTime: string
  completeTime?: string
}

export interface CleanupStaff {
  id: number
  name: string
  phone: string
  status: 'online' | 'offline' | 'busy'
  todayTasks: number
  maxTasks: number
}

// 财务相关类型
export interface WithdrawalRequest {
  id: number
  userId: number
  userName: string
  amount: number
  status: 'pending' | 'approved' | 'rejected'
  createTime: string
  handleTime?: string
  remark?: string
}

export interface WithdrawalQuery extends PaginationParams {
  userId?: number
  status?: string
  startTime?: string
  endTime?: string
}

// 内容管理相关类型
export interface BannerItem {
  id: number
  title: string
  imageUrl: string
  linkUrl?: string
  sort: number
  status: 'active' | 'inactive'
  createTime: string
}

export interface BannerItemForm {
  title: string
  imageUrl: string
  linkUrl?: string
  sort: number
  status: 'active' | 'inactive'
}

export interface BannerGroup {
  id: number
  name: string
  description?: string
  bannerItems: BannerItem[]
  deviceIds: number[]
  sort: number
  status: 'active' | 'inactive'
  createTime: string
  updateTime: string
}

export interface BannerGroupForm {
  name: string
  description?: string
  bannerItems: BannerItemForm[]
  deviceIds: number[]
  sort: number
  status: 'active' | 'inactive'
}

export interface BannerPushRecord {
  id: number
  bannerGroupId: number
  bannerGroupName: string
  deviceIds: number[]
  deviceNames: string[]
  pushTime: 'immediate' | 'schedule'
  scheduleTime?: string
  pushMode: 'replace' | 'append'
  status: 'pending' | 'success' | 'failed'
  createTime: string
  completeTime?: string
}

// 系统管理相关类型
export interface Admin {
  id: number
  username: string
  email: string
  role: string
  status: 'active' | 'disabled'
  lastLoginTime?: string
  createTime: string
}

export interface AdminForm {
  username: string
  email: string
  password?: string
  role: string
  status: 'active' | 'disabled'
}

export interface Role {
  id: number
  name: string
  description: string
  permissions: string[]
  createTime: string
}

export interface RoleForm {
  name: string
  description: string
  permissions: string[]
}

// 登录相关类型
export interface LoginForm {
  username: string
  password: string
}

export interface LoginResponse {
  token: string
  userInfo: {
    id: number
    username: string
    email: string
    role: string
    permissions: string[]
  }
}

// 统计相关类型
export interface DashboardStats {
  totalUsers: number
  totalDevices: number
  todayDisposals: number
  totalRevenue: number
  userGrowth: number
  deviceOnlineRate: number
  disposalGrowth: number
  revenueGrowth: number
}

export interface ChartData {
  labels: string[]
  datasets: {
    label: string
    data: number[]
    backgroundColor?: string
    borderColor?: string
  }[]
}

// 质检统计类型
export interface QualityStats {
  pendingCount: number
  processedCount: number
  totalDeductions: number
  totalAdditions: number
  exceptionTypes: {
    type: string
    count: number
  }[]
  processingTrend: {
    date: string
    count: number
  }[]
}
